<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/sample.html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
		<style type="text/css">
			body,
			html,
			#allmap {
				width: 100%;
				height: 100%;
				overflow: hidden;
				margin: 0;
				font-family: "微软雅黑";
			}

			#l-map {
				height: 100%;
				width: 78%;
				float: left;
				border-right: 2px solid #bcbcbc;
			}

			#r-result {
				height: 100%;
				width: 20%;
				float: left;
			}

			/*去除百度地图版权*/
			.anchorBL {
				display: none;
			}
		</style>
		<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=3.0&ak=BC76a27687a33d846d9940a36844ccd7"></script>
		<title>当前设备位置</title>
	</head>
	<body>
		<div id="allmap"></div>
	</body>
	<script type="text/javascript">
		// 百度地图API功能
		var map = new BMap.Map("allmap", {
			mapType: BMAP_HYBRID_MAP
		});
		var myWorkPoint = new BMap.Point(112.509875, 34.694541); //图书馆位置
		map.centerAndZoom(myWorkPoint, 18); //设置地图中心，缩放比例
		map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放

		var top_left_control = new BMap.ScaleControl({
			anchor: BMAP_ANCHOR_TOP_LEFT
		}); // 左上角，添加比例尺
		map.addControl(top_left_control); // 添加控件
		
		var already = [];
		function addMarker(x, y) {
			removeOverlay(); //清除上一个标记点
			var convertor = new BMap.Convertor();
			var point2 = new BMap.Point(y, x); // 创建传入点
			var pointArr = [];
			pointArr.push(point2);
			convertor.translate(pointArr, 1, 5, translateCallback)
			// map.centerAndZoom(point2,18);	//设置地图中心，缩放比例
			// var marker = new BMap.Marker(point2);	// 创建标注
			// map.addOverlay(marker);	// 将标注添加到地图中
			// marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
		};
		//坐标转换完之后的回调函数
		translateCallback = function(data) {
			if (data.status === 0) {
				var marker = new BMap.Marker(data.points[0]);
				already.push(data.points[0])
				map.addOverlay(marker);
				var label = new BMap.Label("当前位置", {
					offset: new BMap.Size(20, -10)
				});
				marker.setLabel(label); //添加百度label
				map.setCenter(data.points[0]);
				//wyy();
			}
		};

		//向map添加折线
		function wyy() {
			// 创建折线
			var polyline = new BMap.Polyline(already, {
				strokeColor: 'blue',
				strokeWeight: 10,
				strokeOpacity: 0.5
			});
			map.addOverlay(polyline); // 增加折线
		}
		
		// 清除覆盖物
		function removeOverlay() {
			map.clearOverlays();
		};
	</script>
</html>
